<template>
    <div>
        <a href="/Addk">新增科室</a>
        <br>
        <a href="https://localhost:7261/api/KHouse/DaoChu">导出科室信息表</a>
        <h1>显示科室列表</h1>
        科室名称:<input type="text" v-model="ts.name">
        日期:<input type="date" v-model="ts.d1">-<input type="date" v-model="ts.d2">
        <input type="button" value="查询" @click="xx">
        <input type="button" value="重置" @click="xxx">
        <table class="table">
            <thead>
                <tr>
                    <td>科室编号</td>
                    <td>科室名称</td>
                    <td>科室人数</td>
                    <td>科室描述</td>
                    <td>创建日期</td>
                    <td>是否删除</td>
                    <td>操作列</td>
                </tr>
            </thead>
            <thead>
                <tr v-for="a in date">
                    <td>{{ a.kHouseId }}</td>
                    <td>{{ a.kHouseName }}</td>
                    <td>{{ a.people }}</td>
                    <td>{{ a.miaoshu }}</td>
                    <td>{{ moment(a.kTimes).format("YYYY-MM-DD HH:MM:SS") }}</td>
                    <td>{{ a.isDelete }}</td>
                    <td>
                        <input type="button" value="编辑" @click="upd(a.kHouseId)">
                        <input type="button" value="逻辑删除" @click="del(a.kHouseId)">
                    </td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
const routher = useRouter()
onMounted(()=>{
    show()
})
//查询
const xx=()=>{
    show()
}
//重置
const xxx=()=>{
    ts.value={
    name:'',
    d1:null,
    d2:null
    }
}
const del=(val:any)=>{
    if(!confirm("确认删除吗")){
        return
    }
    axios.delete("/api/KHouse/DelHouse",{params:{id:val}}).then(res=>{
        if(res.data>0){
            alert("删除成功")
            show()
        }
        else{
            alert("删除失败")
        }
    })
}
const upd=(val:any)=>{
    routher.push({path:"/Updatek",query:{id:val}})
}
const ts=ref({
    name:'',
    d1:null,
    d2:null
})
const show=()=>{
    axios.get("/api/KHouse/ShowKhouse",{params:ts.value}).then(res=>{
        date.value=res.data
    })
}
const date=ref([{
    "kHouseId": 0,
    "kHouseName": "",
    "people": 0,
    "miaoshu": "",
    "kTimes": "",
    "isDelete": false
}])
</script>

<style scoped>

</style>